package com.weedsdream.fileselect

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.luck.picture.lib.entity.LocalMedia
import com.weedsdream.BaseActivity

//用于Compose测试时模拟测试环境
internal class TestActivity : BaseActivity() {
    /**用于Ui监视的列表,其中first代表类型：video,image,audio,second为地址*/
    private val medias = mutableStateListOf<LocalMedia>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MainUi()
        }
    }

    @Composable
    fun MainUi() {
        Column(
            modifier = Modifier
                .fillMaxSize()
                .background(Color.White)
        ) {
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(60.dp)
                    .background(Color.Cyan)
            ) {
                Box(modifier = Modifier
                    .size(40.dp)
                    .background(Color.Blue)
                    .align(Alignment.CenterVertically)
                    .clickable {
                        ImageSelector.openPicture(medias) {
                            medias.clear()
                            medias.addAll(it)
                        }
                    }) {

                }
            }
            LazyRow(
                Modifier
                    .fillMaxWidth()
                    .height(80.dp)
                    .background(Color.LightGray)
            ) {
                for (media in medias.withIndex()) {
                    item {
                        AsyncImage(model = media.value.path, contentDescription = null,
                            modifier = Modifier
                                .size(60.dp)
                                .padding(10.dp)
                                .background(Color.DarkGray)
                                .clickable {
                                    ImageSelector.previewPicture(medias, media.index) { position ->
                                        medias.removeAt(position)
                                    }
                                })
                    }
                }
            }
        }
    }
}